﻿using System.Diagnostics;
using Modbus.Messages;

namespace Modbus
{
	partial class ModbusClient
	{
		public bool[] ReadExceptionStatus(byte slaveAddress)
		{
			//
			// Input arguments validation.
			//

			Ensure.ArgumentNotEqualTo(SR.Argument_slaveAddress, slaveAddress, BroadcastAddress);

			//
			// Internal state validation.
			//

			this.ThrowIfDisposed();

			//
			// Request creation.
			//

			ModbusMessage request = new ModbusMessage();
			request.FunctionCode = FunctionCodes.ReadExceptionStatus;

			//
			// Perform transaction.
			//

			var response = this.transport.Request<ReadExceptionStatusResponse>(slaveAddress, request);

			//
			// Prepare return value.
			//

			bool[] bits = DataUtility.DecodeDiscretes(8, response.ExceptionStatus);

			return bits;
		}
	}
}
